package com.aqgj.pubCode.dao;

/**
 * Created by zhg on 2017/9/26.
 */

import com.aqgj.pubCode.bean.CodeTableValue;
import com.aqgj.util.BaseDaoImpl;
import com.aqgj.util.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("codeTableValueDao")
public class CodeTableValueDao extends BaseDaoImpl<CodeTableValue> {
    public CodeTableValueDao() {
    }

    public List<CodeTableValue> queryCodeTableValues(String codeTableId) {
        return this.createQuery("from CodeTableValue t where t.codeTable.id=? and t.codeTableValue is null order by sort asc", new Object[]{codeTableId}).getResultList();
    }

    public boolean isCodeValueExist(String id, String value, String pid) {
        String condition = null;
        if(StringUtils.isNotEmpty(id)) {
            condition = "id!='" + id + "' and";
        }
        return ((Long)this.createQuery("select count(*) from CodeTableValue where " + (condition == null?"":condition) + " value=? and codeTable.id=?", new Object[]{value, pid}).getSingleResult()).longValue() > 0L;
    }
}

